package com.owc.common.enums;

import lombok.Data;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author xiaom
 * @Date 2020/2/27 14:22
 * @Version 1.0.0
 * @Description <>
 **/
public enum ExchangeType {
    ETH_EBC_RATE("ETH_EBC_RATE","ETH兑换EBC汇率",new Mapper("ETH","EBC")),
    USDT_ERC20_EBC_RATE("USDT_ERC20_EBC_RATE","USDT(ERC20)兑换EBC汇率",new Mapper("USDT_ERC20","EBC")),
    EBC_OWC_RATE("EBC_OWC_RATE","EBC兑换OWC汇率",new Mapper("EBC","OWC"));

    private String type;

    private String desc;

    private Mapper mapper;

    ExchangeType(String type, String desc,Mapper mapper) {
        this.type = type;
        this.desc = desc;
        this.mapper = mapper;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public Mapper getMapper() {
        return mapper;
    }

    /**
     * Find by type.
     * @param type type
     * @return ExchangeType enum example.
     */
    public static Optional<ExchangeType> match(String type) {
        return Arrays.stream(ExchangeType.values())
                .filter(t -> t.getType().equals(type))
                .findFirst();
    }

    @Data
    public static class Mapper{

        private String from;

        private String to;

        public Mapper(String from, String to) {
            this.from = from;
            this.to = to;
        }
    }
}
